package com.diy.sigmund.diycommon.middleware.apollo;

import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author ylm-sigmund
 * @since 2021/10/28 17:51
 */
public class ApolloProfileConfigUtil {

    private static final Logger log = LoggerFactory.getLogger(ApolloProfileConfigUtil.class);

    /**
     * 设置spring boot启动的profile
     */
    public static void setProfilesActive() {
        Config applicationConfig = ConfigService.getAppConfig();
        String key = "spring.profiles.active";
        String defaultValue = "dev";
        String profilesActive = applicationConfig.getProperty(key, defaultValue);
        log.info("获取到的profile={}", profilesActive);
        System.setProperty(key, profilesActive);
    }
}
